********************************************************************************
/* Prep data. 
You need two files: (a) the ANES cumulative data file, and (b) the ANES coding 
of the 2008 timing of the vote decision variable. */********************************************************************************

*** Import 2008 coding of timing of vote decision variable

* Recode this variable.
use "anes_2008_Election_decision_Final_codes.dta", clear 

recast double V080001
rename V080001 VCF0006
gen VCF0004 = 2008

*** Time of voting decision for 2008
* See file for coding of variable
recode EDCode (1/5=2) (6/7=1) (8/11=0) (12/96=.), gen(time2008)

* Merge with raw ANES cumulative data file

merge 1:1 VCF0004 VCF0006 using "anes_cdf_original.dta"

**** Generate variables for analysis

drop if VCF0004 < 1980
drop if (VCF0004 == 1982 | VCF0004 == 1986 | VCF0004 == 1990 | VCF0004 == 1994)
drop if (VCF0004 == 1998 | VCF0004 == 2002 | VCF0004 == 2006)

*** Republican vote choice
recode VCF0704(0=.) (3=.), gen (choice)
replace choice = choice - 1

*** President feeling thermometer
recode VCF0428 (98/99=.), gen(ptherm)
replace ptherm = abs(97 - ptherm) if VCF0004==1994
replace ptherm = abs(97 - ptherm) if VCF0004==1996
replace ptherm = abs(97 - ptherm) if VCF0004==1998
replace ptherm = abs(97 - ptherm) if VCF0004==2000
replace ptherm = abs(97 - ptherm) if VCF0004==1980
replace ptherm = abs(97 - ptherm) if VCF0004==1978
replace ptherm = abs(97 - ptherm) if VCF0004==1968
** Lines 15 through 21 are needed to reverse the scale when there is a Democratic president

*** Party ID
recode VCF0301 (0=.), gen(pid10)

*** Economic approval
recode VCF9009 (1=4) (2=3) (4=2) (5=1) (0=.) (8/9=.), gen(economy)
replace economy = abs(5 - economy) if VCF0004==1996
replace economy = abs(5 - economy) if VCF0004==2000
** Lines 29 and 30 are needed to reverse the scale when there is a Democratic president

*** Democratic traits
** Intelligence
recode VCF0350 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(demintell4)
** Compassionate
recode VCF0351 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(demcompass4)
** Decent
recode VCF0352 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(demdec4)
** Inspiring
recode VCF0353 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(demins4)
** Knowledgeable
recode VCF0354 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(demknow4)
** Moral
recode VCF0355 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(demmoral4)
** Leadership
recode VCF0356 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(demlead4)
** Cares
recode VCF0357 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(demcares4)
* Traits
alpha demintell4 demcompass4 demdec4 demins4 demknow4 demmoral4 demlead4 demcares4, item gen(dtraits)

*** Republican traits
** Intelligence
recode VCF0362 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(repintell4)
** Compassionate
recode VCF0363 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(repcompass4)
** Decent
recode VCF0364 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(repdec4)
** Inspiring
recode VCF0365 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(repins4)
** Knowledgeable
recode VCF0366 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(repknow4)
** Moral
recode VCF0367 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(repmoral4)
** Leadership
recode VCF0368 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(replead4)
** Cares
recode VCF0369 (0=.) (8=.) (9=.) (1=4) (2=3) (3=2) (4=1), gen(repcares4)

* Traits scale
alpha repintell4 repcompass4 repdec4 repins4 repknow4 repmoral4 replead4 repcares4, item gen(rtraits)


*** Ideology
recode VCF0803 (0=.) (9=.), gen(ideology)

*** Race 
recode VCF0106(0=.) (9 = .), gen(race)
replace race = race - 1
replace race = 1 if race == 2

*** Gender
recode VCF0104(0=.), gen(gender)
replace gender = gender - 1

*** Union
recode VCF0127(0=.), gen(union)
replace union = union * -1 + 2


*** Time of vote decision
recode VCF0712 (1/3=0) (4=1) (5/6=2) (0=.), gen(time)
replace time = time2008 if VCF0004==2008


*** Strength of PID
recode VCF0305 (0=.), gen(pidstr)
label var pidstr "Traditional strength of Party ID"
** Party Thermometers
recode VCF0224 (98/99=.)
recode VCF0218 (98/99=.)
gen ptstr = abs(VCF0218 - VCF0224)
label var ptstr "Absolute difference in party thermometers"
** Party Affect measure
recode VCF0322 (999=.)
gen pastr = abs(VCF0322)
label var pastr "Absolute difference in party affect"
** Partisanship scale
alpha pidstr ptstr pastr, std item gen(pstrength)
label var pstrength "Strength of partisanship scale"


*** Political knowledge
** Political Knowledge measures
gen ksen=1 if VCF9036==1
replace ksen=1 if VCF9036==2
replace ksen=0 if VCF9036==4
replace ksen=0 if VCF9036==5
replace ksen=0 if VCF9036==8
gen khouse=1 if VCF0729==2
replace khouse=0 if VCF0729==1
gen khouse2=1 if VCF0730==2
replace khouse2=0 if VCF0730==1
gen kcand=1 if VCF0972==1
replace kcand=0 if VCF0972==5
gen kptyideo=1 if VCF0502==2
replace kptyideo=0 if VCF0502==1
replace kptyideo=0 if VCF0502==9
** Knowledge scale
alpha ksen khouse kcand kptyideo khouse2, item gen(pknow)


*** Ambivalence
** Likes of Democratic Presidential Candidate
recode VCF0401 (9=.)
** Dislikes of Democratic Presidential Candidate
recode VCF0402 (9=.)
** Likes of Republican Presidential Candidate
recode VCF0405 (9=.)
** Dislikes of Republican Presidential Candidate
recode VCF0406 (9=.)
** Ambivalence toward the two candidates
gen Dpc = (VCF0401 + VCF0406)/2
gen Rpc = (VCF0405 + VCF0402)/2
gen ambpc = ((Dpc + Rpc)/2) - abs(Dpc - Rpc)
label var ambpc "Ambivalence toward presidential candidates"


*** Battleground states
** From 'Using Battleground States as a Natural Experiment to Test Theories of Voting'
** by Alan S. Gerber, Gregory A. Huber, Conor M. Dowling, David Doherty, and Nicole Schwartzberg
** APSA 2009
gen battle=0
*** 2008 battleground states
replace battle=1 if VCF0901b=="FL" & VCF0004==2008
replace battle=1 if VCF0901b=="OH" & VCF0004==2008
replace battle=1 if VCF0901b=="CO" & VCF0004==2008
replace battle=1 if VCF0901b=="IA" & VCF0004==2008
replace battle=1 if VCF0901b=="IN" & VCF0004==2008
replace battle=1 if VCF0901b=="MO" & VCF0004==2008
replace battle=1 if VCF0901b=="MI" & VCF0004==2008
replace battle=1 if VCF0901b=="NV" & VCF0004==2008
replace battle=1 if VCF0901b=="NH" & VCF0004==2008
replace battle=1 if VCF0901b=="NC" & VCF0004==2008
replace battle=1 if VCF0901b=="OR" & VCF0004==2008
replace battle=1 if VCF0901b=="WI" & VCF0004==2008
replace battle=1 if VCF0901b=="MN" & VCF0004==2008
replace battle=1 if VCF0901b=="PA" & VCF0004==2008
replace battle=1 if VCF0901b=="VA" & VCF0004==2008
replace battle=1 if VCF0901b=="NJ" & VCF0004==2008
replace battle=1 if VCF0901b=="NM" & VCF0004==2008
*** 2004 battleground states
replace battle = 1 if VCF0901b=="FL" & VCF0004==2004
replace battle = 1 if VCF0901b=="OH" & VCF0004==2004
replace battle = 1 if VCF0901b=="PA" & VCF0004==2004
replace battle = 1 if VCF0901b=="MI" & VCF0004==2004
replace battle = 1 if VCF0901b=="WI" & VCF0004==2004
replace battle = 1 if VCF0901b=="NH" & VCF0004==2004
replace battle = 1 if VCF0901b=="NM" & VCF0004==2004
replace battle = 1 if VCF0901b=="IA" & VCF0004==2004
replace battle = 1 if VCF0901b=="ME" & VCF0004==2004
replace battle = 1 if VCF0901b=="WV" & VCF0004==2004
replace battle = 1 if VCF0901b=="MN" & VCF0004==2004
replace battle = 1 if VCF0901b=="NV" & VCF0004==2004
replace battle = 1 if VCF0901b=="AR" & VCF0004==2004
replace battle = 1 if VCF0901b=="AZ" & VCF0004==2004
replace battle = 1 if VCF0901b=="CO" & VCF0004==2004
replace battle = 1 if VCF0901b=="MO" & VCF0004==2004
replace battle = 1 if VCF0901b=="NC" & VCF0004==2004
replace battle = 1 if VCF0901b=="NJ" & VCF0004==2004
replace battle = 1 if VCF0901b=="OR" & VCF0004==2004
replace battle = 1 if VCF0901b=="VA" & VCF0004==2004
*** 2000 battleground states
replace battle = 1 if VCF0901b=="FL" & VCF0004==2000
replace battle = 1 if VCF0901b=="PA" & VCF0004==2000
replace battle = 1 if VCF0901b=="MI" & VCF0004==2000
replace battle = 1 if VCF0901b=="WI" & VCF0004==2000
replace battle = 1 if VCF0901b=="NH" & VCF0004==2000
replace battle = 1 if VCF0901b=="NM" & VCF0004==2000
replace battle = 1 if VCF0901b=="IA" & VCF0004==2000
replace battle = 1 if VCF0901b=="ME" & VCF0004==2000
replace battle = 1 if VCF0901b=="WV" & VCF0004==2000
replace battle = 1 if VCF0901b=="MN" & VCF0004==2000
replace battle = 1 if VCF0901b=="AR" & VCF0004==2000
replace battle = 1 if VCF0901b=="MO" & VCF0004==2000
replace battle = 1 if VCF0901b=="OR" & VCF0004==2000
replace battle = 1 if VCF0901b=="TN" & VCF0004==2000
replace battle = 1 if VCF0901b=="WA" & VCF0004==2000
replace battle = 1 if VCF0901b=="AZ" & VCF0004==2000
replace battle = 1 if VCF0901b=="NV" & VCF0004==2000
replace battle = 1 if VCF0901b=="LA" & VCF0004==2000
replace battle = 1 if VCF0901b=="VT" & VCF0004==2000
replace battle = 1 if VCF0901b=="OH" & VCF0004==2000
*** 1996 battleground states
replace battle = 1 if VCF0901b=="AZ" & VCF0004==1996
replace battle = 1 if VCF0901b=="FL" & VCF0004==1996
replace battle = 1 if VCF0901b=="IA" & VCF0004==1996
replace battle = 1 if VCF0901b=="LA" & VCF0004==1996
replace battle = 1 if VCF0901b=="MO" & VCF0004==1996
replace battle = 1 if VCF0901b=="NH" & VCF0004==1996
replace battle = 1 if VCF0901b=="NM" & VCF0004==1996
replace battle = 1 if VCF0901b=="NV" & VCF0004==1996
replace battle = 1 if VCF0901b=="OH" & VCF0004==1996
replace battle = 1 if VCF0901b=="OR" & VCF0004==1996
replace battle = 1 if VCF0901b=="PA" & VCF0004==1996
replace battle = 1 if VCF0901b=="TN" & VCF0004==1996
replace battle = 1 if VCF0901b=="WA" & VCF0004==1996
replace battle = 1 if VCF0901b=="WI" & VCF0004==1996
*** 1992 battleground states
replace battle = 1 if VCF0901b=="CO" & VCF0004==1992
replace battle = 1 if VCF0901b=="CT" & VCF0004==1992
replace battle = 1 if VCF0901b=="DE" & VCF0004==1992
replace battle = 1 if VCF0901b=="GA" & VCF0004==1992
replace battle = 1 if VCF0901b=="HI" & VCF0004==1992
replace battle = 1 if VCF0901b=="IA" & VCF0004==1992
replace battle = 1 if VCF0901b=="KY" & VCF0004==1992
replace battle = 1 if VCF0901b=="LA" & VCF0004==1992
replace battle = 1 if VCF0901b=="ME" & VCF0004==1992
replace battle = 1 if VCF0901b=="MI" & VCF0004==1992
replace battle = 1 if VCF0901b=="MO" & VCF0004==1992
replace battle = 1 if VCF0901b=="MT" & VCF0004==1992
replace battle = 1 if VCF0901b=="NH" & VCF0004==1992
replace battle = 1 if VCF0901b=="NJ" & VCF0004==1992
replace battle = 1 if VCF0901b=="NM" & VCF0004==1992
replace battle = 1 if VCF0901b=="NV" & VCF0004==1992
replace battle = 1 if VCF0901b=="OH" & VCF0004==1992
replace battle = 1 if VCF0901b=="OR" & VCF0004==1992
replace battle = 1 if VCF0901b=="PA" & VCF0004==1992
replace battle = 1 if VCF0901b=="TN" & VCF0004==1992
replace battle = 1 if VCF0901b=="WI" & VCF0004==1992
*** 1988 battleground states
replace battle = 1 if VCF0901b=="CA" & VCF0004==1988
replace battle = 1 if VCF0901b=="CO" & VCF0004==1988
replace battle = 1 if VCF0901b=="CT" & VCF0004==1988
replace battle = 1 if VCF0901b=="DE" & VCF0004==1988
replace battle = 1 if VCF0901b=="KS" & VCF0004==1988
replace battle = 1 if VCF0901b=="KY" & VCF0004==1988
replace battle = 1 if VCF0901b=="LA" & VCF0004==1988
replace battle = 1 if VCF0901b=="ME" & VCF0004==1988
replace battle = 1 if VCF0901b=="MI" & VCF0004==1988
replace battle = 1 if VCF0901b=="MO" & VCF0004==1988
replace battle = 1 if VCF0901b=="MT" & VCF0004==1988
replace battle = 1 if VCF0901b=="ND" & VCF0004==1988
replace battle = 1 if VCF0901b=="NJ" & VCF0004==1988
replace battle = 1 if VCF0901b=="NM" & VCF0004==1988
replace battle = 1 if VCF0901b=="OH" & VCF0004==1988
replace battle = 1 if VCF0901b=="SD" & VCF0004==1988
replace battle = 1 if VCF0901b=="TX" & VCF0004==1988
replace battle = 1 if VCF0901b=="VT" & VCF0004==1988
*** 1984 battleground states
replace battle = 1 if VCF0901b=="AL" & VCF0004==1984
replace battle = 1 if VCF0901b=="AR" & VCF0004==1984
replace battle = 1 if VCF0901b=="CA" & VCF0004==1984
replace battle = 1 if VCF0901b=="CT" & VCF0004==1984
replace battle = 1 if VCF0901b=="DE" & VCF0004==1984
replace battle = 1 if VCF0901b=="GA" & VCF0004==1984
replace battle = 1 if VCF0901b=="KY" & VCF0004==1984
replace battle = 1 if VCF0901b=="LA" & VCF0004==1984
replace battle = 1 if VCF0901b=="ME" & VCF0004==1984
replace battle = 1 if VCF0901b=="MI" & VCF0004==1984
replace battle = 1 if VCF0901b=="MO" & VCF0004==1984
replace battle = 1 if VCF0901b=="MT" & VCF0004==1984
replace battle = 1 if VCF0901b=="NJ" & VCF0004==1984
replace battle = 1 if VCF0901b=="NM" & VCF0004==1984
replace battle = 1 if VCF0901b=="OH" & VCF0004==1984
replace battle = 1 if VCF0901b=="TN" & VCF0004==1984
replace battle = 1 if VCF0901b=="VT" & VCF0004==1984
*** 1980 battleground states
replace battle = 1 if VCF0901b=="CT" & VCF0004==1980
replace battle = 1 if VCF0901b=="IA" & VCF0004==1980
replace battle = 1 if VCF0901b=="IL" & VCF0004==1980
replace battle = 1 if VCF0901b=="LA" & VCF0004==1980
replace battle = 1 if VCF0901b=="ME" & VCF0004==1980
replace battle = 1 if VCF0901b=="MI" & VCF0004==1980
replace battle = 1 if VCF0901b=="MO" & VCF0004==1980
replace battle = 1 if VCF0901b=="OH" & VCF0004==1980
replace battle = 1 if VCF0901b=="OR" & VCF0004==1980
replace battle = 1 if VCF0901b=="PA" & VCF0004==1980
replace battle = 1 if VCF0901b=="TX" & VCF0004==1980
replace battle = 1 if VCF0901b=="VA" & VCF0004==1980
replace battle = 1 if VCF0901b=="VT" & VCF0004==1980
replace battle = 1 if VCF0901b=="WA" & VCF0004==1980
replace battle = 1 if VCF0901b=="WI" & VCF0004==1980

label var battle "Battleground state"


*** Generate year indicators
gen y1980 = 0
replace y1980 = 1 if VCF0004 == 1980
gen y1982 = 0
replace y1982 = 1 if VCF0004 == 1982
gen y1984 = 0
replace y1984 = 1 if VCF0004 == 1984
gen y1988 = 0
replace y1988 = 1 if VCF0004 == 1988
gen y1992 = 0
replace y1992 = 1 if VCF0004 == 1992
gen y1996 = 0
replace y1996 = 1 if VCF0004 == 1996
gen y2000 = 0
replace y2000 = 1 if VCF0004 == 2000
gen y2004 = 0
replace y2004 = 1 if VCF0004 == 2004


*** Create interactions between time-of-vote-decision and vote choice predictors.
gen timeptherm = time*ptherm
gen timepid10 = time*pid10
gen timedtraits = time*dtraits
gen timertraits = time*rtraits
gen timeideology = time*ideology
gen timegender = time*gender
gen timerace = time*race
gen timeunion = time*union
gen timey1980 = time*y1980
gen timey1984 = time*y1984
gen timey1988 = time*y1988
gen timey1992 = time*y1992
gen timey1996 = time*y1996
gen timey2000 = time*y2000
gen timey2004 = time*y2004


** Transform variance model predictors so that they assume meaningful values at zero 
* For 1980 
* summarize pstrength pknow ambpc if (VCF0004==1980 & rtraits!=. & dtraits!=. & ideology!=. & ambpc!=.)
gen pstrength3y1980 = pstrength - .0332899
gen pknow2y1980 = (pknow - .5223923)/.2951102
gen ambpc3y1980 = ambpc + .1215986 
* For 1984 
* summarize pstrength pknow ambpc if (VCF0004==1984 & rtraits!=. & dtraits!=. & ideology!=. & ambpc!=. & economy !=.)
gen pstrength3y1984 = pstrength - .1908967 
gen pknow2y1984 = (pknow - .6118635)/.3121966
gen ambpc3y1984 = ambpc + .4287169
* For 1988 
* summarize time pstrength pknow ambpc battle if (VCF0004==1988 & rtraits!=. & dtraits!=. & ideology!=. & ambpc!=. & economy !=.)
gen pstrength3y1988 = pstrength - .2241071  
gen pknow2y1988 = (pknow - .6793605)/.3059293 
gen ambpc3y1988 = ambpc + .322093
* For 1992 
* summarize time pstrength pknow ambpc battle if (VCF0004==1992 & rtraits!=. & dtraits!=. & ideology!=. & ambpc!=. & economy !=.)
gen pstrength3y1992 = pstrength - .200324  
gen pknow2y1992 = (pknow - .6695261)/.31737 
gen ambpc3y1992 = ambpc + .3757353
* For 1996 
* summarize time pstrength pknow ambpc battle if (VCF0004==1996 & rtraits!=. & dtraits!=. & ideology!=. & ambpc!=. & economy !=.)
gen pstrength3y1996 = pstrength - .3021973   
gen pknow2y1996 = (pknow - .8068687)/.2865771 
gen ambpc3y1996 = ambpc + .3633333
* For 2000 
* summarize time pstrength pknow ambpc battle if (VCF0004==2000 & rtraits!=. & dtraits!=. & ambpc!=. & economy !=.)
gen pstrength3y2000 = pstrength - .209018   
gen pknow2y2000 = (pknow - .5844113)/.3759012 
gen ambpc3y2000 = ambpc + .4845771
* For 2004 
* summarize time pstrength pknow ambpc battle if (VCF0004==2004 & rtraits!=. & dtraits!=. & ideology!=. & ambpc!=. & economy !=.)
gen pstrength3y2004 = pstrength - .3087107  
gen pknow2y2004 = (pknow - .6964006)/.3275133
gen ambpc3y2004 = ambpc + .64241
* For 2008 
* summarize time pstrength pknow battle if (VCF0004==2008 & ideology !=. & economy !=.)
gen pstrength3y2008 = pstrength - .3114887    
gen pknow2y2008 = (pknow - .626898)/.3566537


*** For pooled models
* pknow is (nearly) centered by subtracting a value close to the median, .6666667,
* which allows the mean to be close to zero and for observations to actually 
* assume this value.
* summarize pknow if (VCF0004 < 2008 & ptherm !=. & pid10 !=. & dtraits !=. & rtraits !=. & ideology !=. & race !=. & gender!=. & union != . & pstrength != . & ambpc != . & time != . & choice != .)
gen pknow3 = pknow - .6666667
* pstrength is centered with mean at zero. Some observations take this value.
* summarize pstrength if (VCF0004 < 2008 & ptherm !=. & pid10 !=. & dtraits !=. & rtraits !=. & ideology !=. & race !=. & gender!=. & union != . & pstrength != . & ambpc != . & time != . & choice != . & battle != .)
gen pstrength3 = pstrength - .2056878
* ambpc is centered by subtracting the mean. 
* summarize ambpc if (VCF0004 < 2008 & ptherm !=. & pid10 !=. & dtraits !=. & rtraits !=. & ideology !=. & race !=. & gender!=. & union != . & pstrength != . & pknow != . & time != . & choice != . & battle != .)
gen ambpc3 = ambpc + .3837828


********************************************************************************
*** Run models********************************************************************************

**** Table 2

hetprob choice ptherm pid10 dtraits rtraits ideology race gender union if VCF0004 == 1980 [pw=VCF0009a], het(time pstrength3y1980 pknow2y1980 ambpc3y1980 battle)
hetprob choice ptherm economy pid10 dtraits rtraits ideology race gender union if VCF0004 == 1984 [pw=VCF0009a], het(time pstrength3y1984 pknow2y1984 ambpc3y1984 battle)
hetprob choice ptherm economy pid10 dtraits rtraits ideology race gender union if VCF0004 == 1988 [pw=VCF0009a], het(time pstrength3y1988 pknow2y1988 ambpc3y1988 battle)
hetprob choice ptherm economy pid10 dtraits rtraits ideology race gender union if VCF0004 == 1992 [pw=VCF0009a], het(time pstrength3y1992 pknow2y1992 ambpc3y1992 battle)
hetprob choice ptherm economy pid10 dtraits rtraits ideology race gender union if VCF0004 == 1996 [pw=VCF0009a], het(time pstrength3y1996 pknow2y1996 ambpc3y1996 battle)
hetprob choice ptherm economy pid10 dtraits rtraits race gender union if VCF0004 == 2000 [pw=VCF0009a], het(time pstrength3y2000 pknow2y2000 ambpc3y2000 battle)
hetprob choice ptherm economy pid10 dtraits rtraits ideology race gender union if VCF0004 == 2004 [pw=VCF0009a], het(time pstrength3y2004 pknow2y2004 ambpc3y2004 battle)
hetprob choice ptherm economy pid10 ideology race gender union if VCF0004 == 2008 [pw=VCF0009a], het(time pstrength3y2008 pknow2y2008 battle)


*** Table 4

** Model 1 
probit choice ptherm pid10 dtraits rtraits ideology race gender union if (VCF0004 < 2008 & time != . & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .) [pw=VCF0009a]
** Model 2 
probit choice ptherm pid10 dtraits rtraits ideology race gender union y1984 y1988 y1992 y1996 y2000 y2004 if (VCF0004 < 2008 & time != . & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .) [pw=VCF0009a]
** Model 3 
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union if (VCF0004 < 2008 & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .) [pw=VCF0009a], het(time)
** Model 4 
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union y1984 y1988 y1992 y1996 y2000 y2004 if (VCF0004 < 2008 & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .)  [pw=VCF0009a], het(time)
** Model 5 
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union if VCF0004 < 2008 [pw=VCF0009a], het(time pstrength3 pknow3 ambpc3 battle)
** Model 6 
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union y1984 y1988 y1992 y1996 y2000 y2004 if VCF0004 < 2008 [pw=VCF0009a], het(time pstrength3 pknow3 ambpc3 battle)


*** Tables 5 and 6

* Estimate model for Tables 5 and 6
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union y1984 y1988 y1992 y1996 y2000 y2004 timeptherm timepid10 timedtraits timertraits timeideology timerace timegender timeunion timey1984 timey1988 timey1992 timey1996 timey2000 timey2004 if VCF0004 < 2008 [pw=VCF0009a], het(time pstrength3 pknow3 ambpc3 battle)
* Test whether coefficients of set of choice variables interacted with time = 0
test timeptherm timepid10 timedtraits timertraits timeideology timegender timerace timeunion timey1984 timey1988 timey1992 timey1996 timey2000 timey2004


*** Table 7

** Estimate model for early deciders
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union y1984 y1988 y1992 y1996 y2000 y2004 if (time == 0 & VCF0004 < 2008) [pw=VCF0009a], het(pstrength3 pknow3 ambpc3 battle)
** PCP
predict phat_e 
gen phat_e2 = .
replace phat_e2 = 0 
replace phat_e2 = 1 if phat_e >= 0.5
count if (phat_e2 == choice & time == 0 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .)
* PCP = above quantity / 3604
** PRE = (PCP - 1960/3604) / (1 - 1960/3604)
** ePCP
gen epcp_e = phat_e
replace epcp_e = 1 - phat_e if choice == 0
mean epcp_e if(time == 0 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .) // this is ePCP

** Estimate model for middle deciders
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union y1984 y1988 y1992 y1996 y2000 y2004 if (time == 1 & VCF0004 < 2008) [pw=VCF0009a], het(pstrength3 pknow3 ambpc3 battle)
** PCP
predict phat_m
gen phat_m2 = 0
replace phat_m2 = 1 if phat_m >= 0.5
count if (phat_m2 == choice & time == 1 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .)
* PCP = above quantity / 932
** PRE = (PCP - 493/932) / (1 - 493/932)
** ePCP
gen epcp_m = phat_m
replace epcp_m = 1 - phat_m if choice == 0
mean epcp_m if(time == 1 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .)

** Estimate model for late deciders
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union y1984 y1988 y1992 y1996 y2000 y2004 if (time == 2 & VCF0004 < 2008) [pw=VCF0009a], het(pstrength3 pknow3 ambpc3 battle)
** PCP
predict phat_l
gen phat_l2 = 0
replace phat_l2 = 1 if phat_l >= 0.5
count if (phat_l2 == choice & time == 2 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .)
* PCP = above quantity / 915
** PRE = (PCP - 469/915) / (1 - 469/915)
** ePCP
gen epcp_l = phat_l
replace epcp_l = 1 - phat_l if choice == 0
mean epcp_l if(time == 2 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != . & battle!= .)

** Estimate model for late deciders in non-battleground states
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union y1984 y1988 y1992 y1996 y2000 y2004 if (time == 2 & battle==0 & VCF0004 < 2008) [pw=VCF0009a], het(pstrength3 pknow3 ambpc3)
** PCP
predict phat_lnb
gen phat_lnb2 = 0
replace phat_lnb2 = 1 if phat_lnb >= 0.5
count if (phat_lnb2 == choice & time == 2 & battle == 0 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != .)
* PCP = above quantity / 546
** PRE = (PCP - 284/546) / (1 - 284/546)
** ePCP
gen epcp_lnb = phat_lnb
replace epcp_lnb = 1 - phat_lnb if choice == 0
mean epcp_lnb if(time == 2 & battle == 0 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != .)

** Estimate model for late deciders in battleground states
hetprob choice ptherm pid10 dtraits rtraits ideology race gender union y1984 y1988 y1992 y1996 y2000 y2004 if (time == 2 & battle==1 & VCF0004 < 2008) [pw=VCF0009a], het(pstrength3 pknow3 ambpc3)
** PCP
predict phat_lb
gen phat_lb2 = 0
replace phat_lb2 = 1 if phat_lb >= 0.5
count if (phat_lb2 == choice & time == 2 & battle == 1 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != .)
* PCP = above quantity / 369
** PRE = (PCP - 185/369) / (1 - 185/369)
** ePCP
gen epcp_lb = phat_lb
replace epcp_lb = 1 - phat_lb if choice == 0
mean epcp_lb if(time == 2 &  battle == 1 & VCF0004 < 2008 & choice != . & ptherm != . & pid10 != . & dtraits != . & rtraits != . & ideology != . & race != . & gender != . & union != . & pstrength3 != . & pknow3 != . & ambpc3 != .)


